<template>
  <div>
    <Modal
      v-model="modals"
      width="700"
      scrollable
      closable
      :title="titleFrom"
      :mask-closable="false"
      :z-index="1"
      @on-cancel="handleReset"
	  @on-confirm="handleSubmit"
      @on-visible-change="visible"
    >
      <Form ref="formValidate" :model="formValidate" :label-width="110" :rules="ruleValidate" @submit.native.prevent>
        <Row type="flex" :gutter="24">
			<Col v-bind="grid">
	            <FormItem label="姓名" prop="name">
	              <div class="add">
	                <Input v-model="formValidate.name" placeholder="请输入姓名"></Input>
	              </div>
	            </FormItem>
	        </Col>
			<Col v-bind="grid">
	            <FormItem label="生出日期" prop="birthday">
	              <DatePicker
	                class="form-sty"
	                type="date"
	                :value="formValidate.birthday"
	                placeholder="请选择日期"
	                style="width: 100%"
	                format="yyyy-MM-dd"
	                @on-change="formValidate.birthday = $event"
	              ></DatePicker>
	            </FormItem>
	        </Col>
			<Col v-bind="grid">
	            <FormItem label="性别" prop="sex">
	              <RadioGroup v-model="formValidate.sex">
	                <Radio :label="1">男</Radio>
	                <Radio :label="2">女</Radio>
	                <Radio :label="3">其他</Radio>
	              </RadioGroup>
	            </FormItem>
	        </Col>
			<Col v-bind="grid">
	            <FormItem label="联系电话" prop="phone">
	              <Input v-model="formValidate.phone" placeholder="请输入联系电话"></Input>
	            </FormItem>
	        </Col>
			<Col v-bind="grid">
	            <FormItem label="紧急联系人"  prop="contact_id">
				  <div style="display: flex;">
					  <div class="sec">
						  <Select v-model="formValidate.contact_id" placeholder="请选择" element-id="contact_id" clearable>
							<Option v-for="(item, j) in peoples" :value="item.value" :key="j">{{ item.label }} </Option>
						  </Select>
					  </div>
					  <div class="sec" style="margin-left: 10px;">
					    <Input v-model="formValidate.contact_name" placeholder="请输入姓名"></Input>
					  </div>
				  </div>
	            </FormItem>
	        </Col>
			<Col v-bind="grid">
	            <FormItem label="紧急联系电话" prop="contact_phone">
	              <div class="add">
	                <Input v-model="formValidate.contact_phone" placeholder="请输入紧急联系电话"></Input>
	              </div>
	            </FormItem>
	        </Col>
			<Col v-bind="grid">
	            <FormItem label="证件类型"  prop="doc_type_id">
				  <div style="display: flex;">
					  <div class="sec">
						  <Select v-model="formValidate.doc_type_id" placeholder="请选择" element-id="doc_type_id" clearable>
						  	<Option v-for="(item, j) in docs" :value="item.value" :key="j">{{ item.label }} </Option>
						  </Select>
					  </div>
					  <div class="sec" style="margin-left: 10px;">
					    <Input v-model="formValidate.id_no" placeholder="请输入证件号"></Input>
					  </div>
				  </div>
	            </FormItem>
	        </Col>
			<Col v-bind="grid">
	            <FormItem label="推荐来源" prop="rec_id">
	              <Select v-model="formValidate.rec_id" placeholder="请选择" element-id="rec_id" clearable>
	              	<Option v-for="(item, j) in recs" :value="item.value" :key="j">{{ item.label }} </Option>
	              </Select>
	            </FormItem>
	        </Col>
			<Col v-bind="grid">
	            <FormItem label="推荐人" prop="rec_uid">
	              <div class="add">
	                <Input v-model="formValidate.rec_uid" placeholder="请选择推荐人"></Input>
	              </div>
	            </FormItem>
	        </Col>
			<Col v-bind="grid">
	            <FormItem label="客户来源" prop="source_id">
	              <Select v-model="formValidate.source_id" placeholder="请选择" element-id="source_id" clearable>
	              	<Option v-for="(item, j) in sources" :value="item.value" :key="j">{{ item.label }} </Option>
	              </Select>
	            </FormItem>
	        </Col>
			<Col v-bind="grid">
	            <FormItem label="分组" prop="group_id">
	              <Select v-model="formValidate.group_id" placeholder="请选择" element-id="group_id" clearable>
	              	<Option v-for="(item, j) in groups" :value="item.value" :key="j">{{ item.label }} </Option>
	              </Select>
	            </FormItem>
	        </Col>
			<Col v-bind="grid">
	            <FormItem label="标签" prop="tag_id">
	              <Select v-model="formValidate.tag_id" placeholder="请选择" element-id="tag_id" clearable>
	              	<Option v-for="(item, j) in tags" :value="item.value" :key="j">{{ item.label }} </Option>
	              </Select>
	            </FormItem>
	        </Col>
			<Col v-bind="grid">
	            <FormItem label="详细地址" prop="address">
	              <div class="add">
	                <Input v-model="formValidate.address" placeholder="请输入详细地址"></Input>
	              </div>
	            </FormItem>
	        </Col>
			<Col :xs="24">
	            <FormItem label="备注：">
	              <Input
	                placeholder="请输入备注"
	                type="textarea"
	                :rows="4"
	                element-id="remark"
	                v-model="formValidate.remark"
	              />
	            </FormItem>
          </Col>
          
          
        </Row>
      </Form>
	  <div slot="footer">
	    <Button @click="cancel()">取消</Button>
	    <Button type="primary" @click="handleSubmit()">保存</Button>
	  </div>
    </Modal>
    <Modal v-model="modal12" scrollable width="600" title="图标选择" footer-hide>
      <Input
        v-model="iconVal"
        placeholder="输入关键词搜索,注意全是英文"
        clearable
        style="width: 300px"
        @on-change="upIcon(iconVal)"
        ref="search"
      />
      <div class="trees-coadd">
        <div class="scollhide">
          <div class="iconlist">
            <ul class="list-inline">
              <li class="icons-item" v-for="(item, i) in list" :key="i" :title="item.type">
                <Icon :type="item.type" @click="iconChange(item.type)" class="ivu-icon" />
              </li>
            </ul>
          </div>
        </div>
      </div>
    </Modal>
  </div>
</template>

<script>
import { saveApi,ListDicApi} from '@/api/archives';
import icon from '@/utils/icon';
import { getCookies } from '@/libs/util';
export default {
  name: 'menusFrom',
  props: {
    formValidate: {
      type: Object,
      default: null,
    },
    titleFrom: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      arrs: [],
      searchRule: '',
      iconVal: '',
      grid: {
        xl: 12,
        lg: 12,
        md: 12,
        sm: 24,
        xs: 24,
      },
      modals: false,
      modal12: false,
      ruleValidate: {
		name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
		birthday: [{ required: true, message: '请选择出生日期', trigger: 'blur' }],
		phone: [{ required: true, message: '请输入联系电话', trigger: 'blur' }],
      },
      docs: [],
      peoples: [],
      recs: [],
	  groups:[],
      sources: [],
      tags: [],
      valids: false,
      list: icon,
      authType: true,
      search: icon,
	  header: {},
      fileUrl: '/adminapi/file/upload_file/1',
	  files:[]
    };
  },
  watch: {
    'formValidate.header': function (n) {
      this.formValidate.is_header = n ? 1 : 0;
    },
    'formValidate.auth_type': function (n) {
      if (n === undefined) {
        n = 1;
      }
      this.authType = n === 1;
    },
    'formValidate.data': function (n) {},
  },
  computed: {
	  
  },
  methods: {
    init() {
      this.searchRule = '';
      this.arrs = [];
    },
	// 上传成功
	handleSuccess(res, file) {
	  if (res.status === 200) {
		this.files.push(res.data.data);
	    this.$Message.success(res.msg);
	  } else {
	    this.$Message.error(res.msg);
	  }
	},
	handleFormatError(file) {
		
	},
	handleMaxSize(file) {
	  this.$Message.warning('请上传文件30M以内的文件');
	},
	delFile(index){
		this.files.splice(index,1);
	},
	// 上传头部token
	getToken() {
	  this.header['Authori-zation'] = 'Bearer ' + getCookies('token');
	  console.info(this.header);
	},
    handleCreate1(val) {
      this.headerOptionsList.push({
        value: val,
        label: val,
      });
    },
    // 获取客户数据
    getAddFrom() {
		let that = this;
        ListDicApi()
        .then(async (res) => {
			that.docs = res.data['docs'];
			that.peoples = res.data['peoples'];
			that.groups = res.data['groups'];
			that.recs = res.data['recs'];
			that.sources = res.data['sources'];
			that.tags = res.data['tags'];
        })
        .catch((res) => {
          this.$Message.error(res.msg);
        });
    },
	cancel(){
		this.modals = false;
	},
    // 提交
    handleSubmit() {
      this.$refs['formValidate'].validate((valid) => {
        if (valid) {
          this.valids = true;
		  this.formValidate.attach = JSON.stringify(this.files);
          saveApi(this.formValidate)
            .then(async (res) => {
              this.$Message.success(res.msg);
			  this.files = [];
              this.modals = false;
              this.$emit('getList');
              this.getAddFrom();
            })
            .catch((res) => {
              this.$Message.error(res.msg);
            });
        } else {
			if (!this.formValidate.name) return this.$Message.error('请输入姓名！');
			if (!this.formValidate.birthday) return this.$Message.error('请选择出生日期！');
			if (!this.formValidate.phone) return this.$Message.error('请输入联系电话！');
        }
      });
    },
    handleReset() {
      this.modals = false;
      this.authType = true;
      this.$refs['formValidate'].resetFields();
      this.$emit('clearFrom');
    },
  },
  created() {
    this.list = this.search;
    this.getToken();
    this.getAddFrom();
  },
};
</script>

<style scoped>
.trees-coadd {
  width: 100%;
  height: 500px;
  border-radius: 4px;
  overflow: hidden;
}
.scollhide {
  width: 100%;
  height: 100%;
  overflow: auto;
  margin-left: 18px;
  padding: 10px 0 10px 0;
  box-sizing: border-box;
}
.content {
  font-size: 12px;
}

.time {
  font-size: 12px;
  color: #2d8cf0;
}

.icons-item {
  float: left;
  margin: 6px 6px 6px 0;
  width: 53px;
  text-align: center;
  list-style: none;
  cursor: pointer;
  height: 50px;
  color: #5c6b77;
  transition: all 0.2s ease;
  position: relative;
  padding-top: 10px;
}
.icons-item .ivu-icon {
  font-size: 16px;
}
.search-rule {
  display: flex;
  align-items: center;
  padding: 10px;
  background-color: #f2f2f2;
}
.rule {
  display: flex;
  flex-wrap: wrap;
  max-height: 700px;
  overflow: scroll;
}
/*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
.rule::-webkit-scrollbar {
  width: 10px;
  height: 10px;
  background-color: #f5f5f5;
}

/*定义滚动条轨道 内阴影+圆角*/
.rule::-webkit-scrollbar-track {
  border-radius: 4px;
  background-color: #f5f5f5;
}

/*定义滑块 内阴影+圆角*/
.rule::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background-color: #555;
}
.rule-list {
  background-color: #f2f2f2;
  width: 32%;
  margin: 5px;
  border-radius: 3px;
  padding: 10px;
  color: #333;
  cursor: pointer;
  transition: all 0.1s;
}
.rule-list:hover {
  background-color: #c5d1dd;
}
.rule-list div {
  white-space: nowrap;
}
.select-rule {
  background-color: #c5d1dd;
}
.sec{
	width: 100px;
}
.add {
  display: flex;
  align-items: center;
}
.df {
  display: flex;
  justify-content: center;
}

.file{
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	align-items: center;
}

.file:hover{
	background-color: #edf7fe;
}
.close-bg{
	display: inline-block;
	width: 35px;
	height: 35px;
	display: flex;
	flex-direction: row;
	justify-content: center;
	align-items: center;
	margin-right: 15px;;
}

.close-bg:hover{
	cursor: pointer;
}

.close {
	display: inline-block;
	width: 15px;
	height: 2px;
	background: red;
	transform: rotate(45deg);
}

.close::after {
	content: '';
	display: block;
	width: 15px;
	height: 2px;
	background: red;
	transform: rotate(-90deg);
}

</style>
